<!-- inc:head_open -->
<style type="text/css">body{overflow:hidden;margin:2px 0 0 2px;}</style>
<script type="text/javascript" src="{func add_js ueditor/dialogs/internal.js}"></script>
<script type="text/javascript">
function save_pic()
{
	var vals = $("#selected").val();
	if(!vals || vals == "undefined")
	{
		$.dialog.alert("没有选择图片");
		callback(null);
	}
	var list = vals.split(",");
	var htm = "";
	for(var i in list)
	{
		var val = $("#attr_"+list[i]).attr("t3");
		var title = $("#attr_"+list[i]).attr("t1");
		htm += '<p><img src="'+val+'" border="0" alt="'+title+'" title="'+title+'" /></p>';
	}
	editor.execCommand('inserthtml',htm);
	dialog.close();
}

dialog.onok = save_pic;
function user_sort(id)
{
	return function(obj1,obj2){
		var v1 = parseInt(obj1[id]);
		var v2 = parseInt(obj2[id]);
		if(v1 < v2)
		{
			return -1;
		} else if(v1 > v2) {
			return 1;
		} else {
			return 0;
		}
	};
}

function sort_taxis2()
{
	var list = new Array();
	$("input[name=taxis]").each(function(i){
		var s = $(this).attr("data");
		list[i] = s;
	});
	list = list.sort(function(a,b){return a-b;});
	var str = list.join(",");
	$("#selected").val(str);
	load_picture(str);
}

function sort_taxis3()
{
	var list = new Array();
	$("input[name=taxis]").each(function(i){
		var s = $(this).attr("data");
		list[i] = s;
	});
	list = list.sort(function(a,b){
		if(parseInt(a)>parseInt(b))
		{
			return -1;
		}
		else
		{
			return 1;
		}
	});
	var str = list.join(",");
	$("#selected").val(str);
	load_picture(str);
}

function sort_taxis()
{
	var tlist = new Array();
	$("input[name=taxis]").each(function(i){
		var t = $(this).val();
		var s = $(this).attr("data");
		tlist[i] = {"t":t,"v":s};
	});
	var list = tlist.sort(user_sort("t"));
	var vlist = new Array();
	for(var i=0;i<list.length;i++)
	{
		vlist[i] = list[i]["v"];
	}
	var str = vlist.join(",");
	$("#selected").val(str);
	load_picture(str);
}

function add_picture(id)
{
	var str = $("#selected").val();
	if(str && str != "undefined")
	{
		str += ","+id;
	}
	else
	{
		str = id;
	}
	var list = str.split(",");
	list = $.unique(list);
	var new_str = list.join(",");
	$("#selected").val(new_str);
	load_picture(new_str)
}

function delete_picture(id)
{
	var str = $("#selected").val();
	if(str == id)
	{
		$("#selected").val("");
		$("#attr_"+id).show();
		load_picture("");
		return true;
	}
	var list = str.split(",");
	var nlist = new Array();
	var m = 0;
	for(var i in list)
	{
		if(list[i] != id)
		{
			nlist[m] = list[i];
			m++;
		}
	}
	$("#attr_"+id).show();
	var new_str = nlist.join(",");
	$("#selected").val(new_str);
	load_picture(new_str);
	return true;
}

function load_picture(str)
{
	if(!str || str == "undefined")
	{
		str = $("#selected").val();
	}
	if(!str || str == "undefined")
	{
		$("#selected_picture").html('<ul style="list-style:none;margin:0;padding:0"><li><img src="images/blank.gif" width="91px" height="91px"/></li></ul>');
		return false;
	}
	var list = str.split(",");
	var html = '<ul class="piclist">';
	for(var i in list)
	{
		var t1 =$("#attr_"+list[i]).attr("t1");
		var t2 =$("#attr_"+list[i]).attr("t2");
		var t3 =$("#attr_"+list[i]).attr("t3");
		var t4 =$("#attr_"+list[i]).attr("t4");
		var t = (parseInt(i)+1).toString();
		$("#attr_"+list[i]).hide();
		html += '<li title="附件名称：'+t1+'&#10;上传时间：'+t4+'" id="selected_'+list[i]+'">';
		html += '<img src="'+t2+'" width="80px" height="80px" border="0" />';
		html += '<span class="idd">'+list[i]+'</span>';
		html += '<span class="del" onclick="delete_picture(\''+list[i]+'\')"></span>';
		html += '<input type="text" value="'+t+'" name="taxis" data="'+list[i]+'" class="taxis_input" />';
		html += '</li>';
	}
	html += '</ul>';
	$("#selected_picture").html(html);
	$("#selected_html").show();
}
</script>
<div class="tips">
<table cellpadding="0" cellspacing="0">
<tr>
	<form method="post" action="{echo admin_url('uedit','picture')}">
	<td>&nbsp; 关键字：</td>
	<td><input type="text" id="keywords" name="keywords" value="{$keywords}" /></td>
	<td style="padding-left:5px;"><select id="cate_id" name="cate_id">
			<option value="0">请选择分类</option>
			<!-- $catelist AS $key=>$value -->
			<option value="{$value.id}"{if $value.id == $cate_id} selected="selected"{/if}>{$value.title}</option>
			<!-- end -->
		</select>
	</td>
	<td style="padding-left:5px;"><input type="submit" value="搜索" class="submit" /></td>
	</form>
</tr>
</table>
</div>
<input type="hidden" id="selected" value="" />
<div id="selected_html">
	<div id="selected_picture"><ul style="list-style:none;margin:0;padding:0"><li><img src="images/blank.gif" width="91px" height="91px"/></li></ul></div>
	<div class="clear"></div>
	<div class="tips" align="right">
	<table>
	<tr>
		<td>↑↑↑ 已选择要插入的图片，不支持翻页，翻页前请先提交&nbsp; &nbsp;</td>
		<td><input type="button" value="手工排序" class="button" onclick="sort_taxis()" /></td>
		<td><input type="button" value="ID顺序" class="button" onclick="sort_taxis2()" /></td>
		<td><input type="button" value="ID倒序" class="button" onclick="sort_taxis3()" /></td>
	</tr>
	</table>
	</div>
</div>
<ul class="piclist" id="piclist">
	<!-- loop from=$rslist key=$key value=$value -->
	<li id="attr_{$value.id}" t1="{$value.title}" t2="{$value.ico}" t3="{$value.filename}" t4="{echo date('Y-m-d H:i:s',$value['addtime'])}" title="附件名称：{$value.title}&#10;上传时间：{echo date('Y-m-d H:i:s',$value['addtime'])}" onclick="add_picture('{$value.id}')"><img src="{$value.ico}" width="80px" height="80px" border="0" /></li>
	<!-- /loop -->
</ul>
<div class="clear"></div>
<!-- if $pagelist -->
<div class="table"><!-- include tpl=pagelist --></div>
<!-- /if -->

<!-- inc:foot_open -->